package com.seeyon.apps.kk.form.workflowevent;

import java.util.List;
import java.util.Map;

import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;

import com.seeyon.ctp.common.constants.ApplicationCategoryEnum;
import com.seeyon.ctp.workflow.event.WorkflowEventData;
import com.seeyon.ctp.workflow.event.WorkflowEventResult;
import com.seeyon.kk.utils.CAP4FormKitUtils;

/**
 *
 * SEEP回填信息校验事件
 * 
 * @author Administrator
 *
 */
public class SeepExtendPlug extends KkBaseExtendPlug {

	@Override
	public String getId() {
		// TODO Auto-generated method stub
		return "kkSeepExtendPlug";
	}

	@Override
	public String getLabel() {
		// TODO Auto-generated method stub
		return "SEEP回填信息校验事件";
	}

	public ApplicationCategoryEnum getAppName() {
		return ApplicationCategoryEnum.form;
	}
	
	/**
	 * 返回指定的模版编号
	 * 
	 * @return
	 */
	public String getTemplateCode() {
		return "";
	};

	// 处理前事件
	public WorkflowEventResult onBeforeFinishWorkitem(WorkflowEventData data) {

		Map<String, Object> formdata = data.getBusinessData();
		String po = MapUtils.getString(formdata, "field0196");
		List<Map<String, Object>> vl = this.kkJdbcTemplate.queryForList("select * from formmain_0131 where field0001=?",
				po);
		if (vl.isEmpty()) {
			WorkflowEventResult wr = new WorkflowEventResult();
			wr.setAlertMessage("PONO 不存在 不允许审批通过");
			return wr;
		}

		if (!vl.isEmpty()) {
			Map<String, Object> vm = vl.get(0);
			if (!StringUtils.equals("回填完成", MapUtils.getString(vm, "field0030"))) {
				WorkflowEventResult wr = new WorkflowEventResult();
				wr.setAlertMessage("SEEP回填状态不是回填完成 不允许审批通过");
				return wr;
			}

		}
		return null;
	}

}
